// 返回一个数组,数组里面包含两个用户信息
const userList = () => {
  return [
    {
      id: 1,
      avatar:
        'https://wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif',
      username: 'admin',
      nickname: '平台管理员',
      password: '11111',
      desc: '平台管理员',
      roles: ['平台管理员'],
      buttons: ['cuser.detail'],
      routes: ['home'],
      token: 'Admin Token'
    },
    {
      id: 2,
      avatar:
        'https://wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif',
      username: 'system',
      nickname: '系统管理员',
      password: '11111',
      desc: '系统管理员',
      roles: ['系统管理员'],
      buttons: ['cuser.detail', 'cuser.user'],
      routes: ['home'],
      token: 'System Token'
    }
  ]
}

// 对外暴露一个数组:数组里面包含两个接口
// 登录假的接口
// 获取用户信息的假的接口
export default [
  // 用户登录接口
  {
    url: '/mock/user/login',
    method: 'post',
    response: ({ body }) => {
      const { username, password } = body
      const checkUser = userList().find(
        (item) => item.username === username && item.password === password
      )
      if (!checkUser) {
        return { code: 201, data: { message: '账号或密码不正确' } }
      }
      const { token } = checkUser
      return { code: 200, data: { token } }
    }
  },
  // 获取用户信息
  {
    url: '/mock/user/info',
    method: 'get',
    response: (request: { headers: { token: any } }) => {
      const token = request.headers.token
      const checkUser = userList().find((item) => item.token === token)

      if (!checkUser) {
        return { code: 201, data: { message: '获取用户信息失败' } }
      }
      return { code: 200, data: { checkUser } }
    }
  }
]
